Skip to content

Explain how to rebuild an unreadable cache on archive queries - #438

Merged
daaain merged 3 commits into
daaain:mainfrom
izbari:fix/search-corrupt-cache
Dec 6, 2026
Merged

daaain merged 3 commits into
daaain:mainfrom
izbari:fix/search-corrupt-cache

Conversation

@izbari

@izbari izbari commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #335.

With an unreadable SQLite cache, opening an archive with serve --no-convert leaves the page available, but searching or loading the project filter returns HTTP 500 with a generic internal error. Restarting with the same flag preserves the damaged cache.

The two read endpoints now translate a recognized SQLite corruption error into the existing HTTP 400 error contract and explain how to rebuild the cache. Other database errors retain their existing handling. The page's initial index warning also specifies that the restart must omit --no-convert.

Two real HTTP requests against a temporary invalid SQLite file returned 500 on main. The regression tests now get 400 and the recovery instruction for both routes. The archive page, search and server suites passed locally (184 tests).

Implemented and verified with OpenAI Codex (GPT-6).

Summary by CodeRabbit

  • Bug Fixes
    • Search and project requests now show a clear error when the local cache is unreadable, with guidance to restart without --no-convert.
    • Search-index messages now distinguish an index that is unavailable from one that can be built by restarting the server without --no-convert.
    • The search page’s rebuild-status hint now includes the reported reason and indicates whether restarting with the appropriate option can build the index.

@coderabbitai

coderabbitai Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The search and projects API routes now return readable client errors for recognized SQLite cache corruption. The unavailable-index message gives conditional guidance about restarting without --no-convert. Tests cover the API responses and both index availability states.

Changes: Corrupt cache error handling

Layer / File(s) Summary
Handle corrupt caches on API routes
claude_code_log/api.py, test/test_server.py
A shared error handler converts recognized corruption errors on the search and projects routes into recovery-instruction errors. Tests verify HTTP 400 responses for both routes when the cache contains invalid SQLite data.
Show conditional index recovery guidance
claude_code_log/html/templates/archive_search.html, test/test_archive_search_page.py, test/__snapshots__/test_snapshot_html.ambr
The unavailable-index message includes restart guidance only when the index is available to build. Browser tests and the snapshot cover both availability states.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Possibly related PRs

Suggested reviewers: daaain

Merge Risk: Minimal · up to 6bb5a

Corrupt cache databases now produce a readable client error with rebuild guidance instead of a generic 500 on the search and projects routes. The rebuild hint is omitted when SQLite lacks FTS5. Tests cover the changed behavior and no concrete merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: the archive query endpoints now return a readable error with cache-rebuild guidance when the cache is unreadable. It is specific and concise, and a teammate scanning h…
Linked Issues check Passed [#335] The issue requires that /api/search and /api/projects return a readable non-500 error for a corrupt cache. At the reviewed head, claude_code_log/api.py defines _report_unreadable_cache.…
Out of Scope Changes check Passed All changes relate to [#335]. The api.py changes add the corruption-translation helper and apply it to the two read endpoints named in the issue. The archive_search.html change and its snapshot up…
Full details: Title check

Explanation

The title names the main change: the archive query endpoints now return a readable error with cache-rebuild guidance when the cache is unreadable. It is specific and concise, and a teammate scanning history would understand the primary change. The title's wording ('Explain how to rebuild') is slightly narrower than the full change, which also converts errors to HTTP 400 responses, but it still refers to the main point of the change.

Full details: Linked Issues check

Explanation

[#335] The issue requires that /api/search and /api/projects return a readable non-500 error for a corrupt cache. At the reviewed head, claude_code_log/api.py defines _report_unreadable_cache. It catches sqlite3.DatabaseError, re-raises non-corruption errors, and raises ValueError for corruption with the text "The cache database is unreadable. Restart the server without --no-convert to rebuild the cache." Both SearchApi.search and SearchApi.projects carry @_report_unreadable_cache(). ArchiveServer maps ValueError to HTTP 400, so both routes return 400 with a readable reason. The projects row iteration runs inside the decorated body, so lazy query errors are covered too. /api/ping is unchanged, as the issue expects. The change since the previous review updates archive_search.html so the unavailable-index hint gives the restart-without---no-convert advice only when index.available is not false. The commit subject indicates that available tracks FTS5 support, so an unreadable cache should still receive the rebuild advice. I could not read index_status in search.py (output truncated), so the exact available value for a corrupt cache is unverified. The parameterized regression test in test/test_server.py and the browser test in test/test_archive_search_page.py were described in the summary only; I did not execute them.

Full details: Out of Scope Changes check

Explanation

All changes relate to [#335]. The api.py changes add the corruption-translation helper and apply it to the two read endpoints named in the issue. The archive_search.html change and its snapshot update adjust the recovery hint the issue requests. The FTS5 condition in the hint (the commit "Only suggest rebuilding search when SQLite supports FTS5") refines that same hint, so the issue's advice does not appear for FTS5-less builds where restarting cannot help. The browser test and server test cover the hint and the two routes. Other database errors are re-raised unchanged. I found no unrelated changes in the reviewed api.py content or the change summary. The template and snapshot changes rest on the summary, because the template output was truncated and I could not confirm the conditional text in full.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c42e4c97-72d2-4af9-865a-50da8167bfa6
Commits

Reviewing files that changed from the base of the PR and between 7cb2ccd and 6bb5a80.

Files selected for processing: 4

  • claude_code_log/html/templates/archive_search.html
  • test/__snapshots__/test_snapshot_html.ambr
  • test/test_archive_search_page.py
  • test/test_server.py

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@daaain

daaain commented Dec 5, 2026

Copy link
Copy Markdown
Owner

Thanks, this follows the direction in #335 closely, and the ValueError → 400 route keeps local paths out of the response the way the server intends.

One thing in the template: the new hint applies to every !index.ready state, including reason: "SQLite was built without FTS5", where restarting without --no-convert won't build anything. index.available already tells the two apart (it's false only for the FTS5 case), so something like:

statusEl.textContent =
    'Search index unavailable: ' + (index.reason || 'not built') +
    (index.available === false ? '.' : '. Restart the server without --no-convert to build the index.');

Nit: json and SearchApi can be imported at the top of test/test_server.py rather than inside the test.

@daaain
daaain merged commit 669c29d into daaain:main Dec 6, 2026
17 checks passed
@daaain

daaain commented Dec 6, 2026

Copy link
Copy Markdown
Owner

Thanks a lot, really appreciate the quick turnaround!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

serve: /api/search and /api/projects return a raw 500 on a corrupt cache database

2 participants